package me.zk.practice1.hw;

import java.util.Scanner;

/**
 * @author zhangkai
 * @date 2023/8/9 12:53
 */
public class HWBJ46 {
    //32 01 00 AE 90 02 00 01 02 30 03 00 AB 32 31 31 02 00 32 33 33 01 00 CC
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        String tagStr = scanner.nextLine();

        String target = scanner.nextLine();
        String[] tags = tagStr.split(" ");

        int index = 0;

        boolean isMatch = false;
        int len = 0;
        while (index < tags.length) {
            String tag = tags[index];
            if (isMatch) {
                break;
            } else {
                len = getLen(tags[index+1],tags[index+2]);
                if (tag.equals(target)) {
                    isMatch= true;
                } else {
                    index+=len;
                }
                index+=2;
            }
            index++;
        }
        StringBuilder s = new StringBuilder();
        for (int i = 0; i < len; i++) {
            s.append(tags[index + i]);
            if (i != len-1) {
                s.append(" ");
            }
        }
        System.out.println(s);
    }

    public static int getLen(String s1, String s2) {

        return Integer.parseInt(s2+s1,16);
    }
}
